function autoScroll(url,appendBlock,loaderBlock){

    var thisPageNum = 2;
    var thisWork = 1;
    var breakAjax=0; //last request result
    var url = url || "";

    $(document).ready(function(){

        // check if is scroll on the page
        if($(document).height() === $(window).height() && breakAjax === 0){
            getNextP();
        }

        $(window).scroll(function(){
            //check if scroll is at the end of page
            if($(window).scrollTop() === $(document).height() - $(window).height() && breakAjax === 0){
                getNextP();
            }
        });
    });

    function getNextP(){
        if(thisWork == 1){
            thisWork = 0;
            loaderBlock.css('display','block');
            $.get(url+thisPageNum+"/true/", function(data){
                if(data==''){
                    breakAjax=1;
                }
                loaderBlock.css('display','none');
                appendBlock.append(data);
                thisPageNum = thisPageNum + 1;
                thisWork = 1;
            });


        }
    }
};


